﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MS.InformationManagement.Presenter.Support;
using MS.InformationManagement.BLL.DocumentPrinter;
using MS.InformationManagement.DAL.DocumentCenter;
using MS.InformationManagement.BLL.DeliveryForms;
using MS.InformationManagement.DAL.DTOs;
using MS.InformationManagement.Support;
using MS.InformationManagement.Support.Constants;
using MS.InformationManagement.Core.TransactionsResponse;

namespace MS.InformationManagement.Presenter.DocumentPrinter
{
    public class DeliveryDocumentPresenter : BasePresenter<IDeliveryDocumentsView>
    {

        #region Constructors

        public DeliveryDocumentPresenter(IDeliveryDocumentsView view) : base(view) { }

        #endregion

        #region Public Methods

        public void HandleLoad()
        {
            //Getting Pending Deliveries
            int totalRecords = 0;
            View.DeliveryZones = DocumentDeliveryBagBLL.GetDeliveryZones();
            View.PendingDeliveries = DocumentDeliveryBagBLL.GetDocumentsForShippingDelivery(View.PageIndex, View.PageSize, out totalRecords);
            View.TotalItems = totalRecords;
            View.Show();
        }

        public void LoadInitialData()
        {
            //Getting Delivery Means
            View.DeliveryMeans = DocumentDeliveryBagBLL.GetDeliveryMeans();
            View.LoadInitialData();
        }

        public void DeliveryFormGeneration()
        { 
            //Get selected items
            Planilla deliveryForm = DocumentDeliveryBagBLL.GetDeliveryForm(View.SelectedDeliveryId, View.SelectedDeliveryZone);
            List<DeliveryFormDTO> deliveryRows = DocumentDeliveryBagBLL.GetDeliveryRows(deliveryForm);

            //Generate form for selected items
            DeliveryFormsCommand deliveryCommand = new DeliveryFormsCommand(deliveryForm, deliveryRows, ConfigurationHelper.GetInstance().ConfigItems[GlobalConstants.ENTITY_NAME]);
            DeliveryFormCreationResponse deliveryResponse = deliveryCommand.Execute() as DeliveryFormCreationResponse;
            View.DeliveryFormResponse = deliveryResponse;
            View.ShowDeliveryForm();
        }

        #endregion



    }
}
